package com.jjtm.common.core.utils.security;

import org.apache.commons.codec.binary.Base64;

import java.nio.charset.StandardCharsets;

/**
 * @author wangbaofeng
 */
public class Base64Utils {

    /**
     * 解密
     *
     * @param data data
     * @return String
     * @author jqlin
     */
    public static String decode(String data) {
        if (null == data) {
            return null;
        }

        return new String(Base64.decodeBase64(data.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
    }

    /**
     * 加密
     *
     * @param data data
     * @return String
     * @author jqlin
     */
    public static String encode(String data) {
        if (null == data) {
            return null;
        }
        return new String(Base64.encodeBase64(data.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
    }
}
